 
 ;  FUNCTION INPUT(PORT) AND FUNCTION OUTPUT(PORT)
 ;  INPUT AND OUTPUT FROM SPECIFIED I/O PORTS. FUNCTIONS RETURN VALUES
 ;  AS INTEGERS FOR MORE CONVENIENT TESTING.
 ;  PORT RANGE MUST BE BETWEEN 0 AND 255. (NO TESTING IS DONE)
 ;  I:=INPUT(2)     J:=OUTPUT(10)
        
        .FUNC   INPUT,1         ;ONE ARGUMENT
        POP     HL              ;RETURN ADDR
        POP     DE              ;ZERO
        POP     DE              ;ZERO
        POP     DE              ;ARGUMENT
        LD      A,E             ;LOW BYTE TO A
        LD      ($+4),A         ;MAKE INPUT CMND
        IN      A,(0)           ;INPUT TO A
        LD      E,A             ;DATA INPUT TO E
        PUSH    DE              ;BACK ON STACK
        JP      (HL)            ;EXIT
        .END
 
 ;  PROCEDURE  OUTPUT(PORT,NUMBER)
 ;  INPUT AND OUTPUT FROM SPECIFIED I/O PORTS. FUNCTIONS RETURN VALUES
 ;  AS INTEGERS FOR MORE CONVENIENT TESTING.
 ;  PORT RANGE MUST BE BETWEEN 0 AND 255. (NO TESTING IS DONE)
 ;  OUTPUT(10,65)
        
        .PROC   OUTPUT,2        ;ONE ARGUMENT
        POP     HL              ;RETURN ADDR
        POP     BC              ;ARGUMENT 2 (NUMBER)
        POP     DE              ;ARGUMENT 1 (PORT)
        LD      A,E             ;LOW BYTE TO A
        LD      ($+5),A         ;MAKE OUTPUT CMND
        LD      A,C             ;NUMBER TO A
        OUT     (0),A           ;OUTPUT TO A
        JP      (HL)            ;EXIT
        .END

;  THIS FUNCTION CALLS THE CP/M CONSOLE READY ENTRY POINT AND RETURNS
;  A BOOLEAN VALUE (TRUE OR FALSE). CODE WILL OPERATE ON EITHER 8080 OR Z80
;

        .FUNC   READY           ;TESTS CONSOLE CHAR READY AND RETURNS T ! F
        POP     DE              ;RETURN ADDR
        POP     HL
        POP     HL              ;ZEROS
        LD      L,06H           ;CP/M CONSOLE READY ENTRY POINT
        CALL    BIOS
        LD      L,A
        PUSH    HL              ;BOOLEAN RESULT TO STACK
        EX      DE,HL           ;RETURN ADDR TO HL
HERE:   JP      (HL)            ;EXIT
BIOS:   LD      A,(0002H)       ;PAGE NO IN LOCATION 02H
        LD      H,A
        JP      (HL)
        .END

*****************************
What follows is another version of the above.
*****************************
        ;
        ;
        .FUNC   STAT,3
;
        POP     HL      ;GET RETURN ADDRESS
        POP     DE      ;GET ZERO
        POP     BC      ;GET ZERO
        POP     BC      ;GET MASK
        POP     DE      ;GET EXPECTED RESULT
        LD      D,C
        POP     BC      ;GET PORT
        LD      A,C     ;PUT PORT IN A
        LD      ($1+1),A  ;STUFF PORT
$1      IN      A,(0)     ;PORT LOADED ABOVE
        AND     D       ;AND DATA & MASK
        CP      E       ;COMPARE WITH EXPECTED RESULTS
        JP      NZ,$2
        LD      DE,1    ;LOAD BOOLEAN TRUE
        PUSH    DE      ;RETURN RESULT ON STACK
        JP      (HL)
$2      LD      DE,0    ;LOAD BOOLEAN FALSE
        PUSH    DE      ;RETURN RESULT ON STACK
        JP      (HL)    ;RETURN
;
;
        .FUNC   INPUT,2
        ;
        POP     HL      ;GET RETURN ADDRESS
        POP     DE      ;GET ZERO
        POP     BC      ;GET ZERO
        POP     DE      ;GET MASK
        POP     BC      ;GET INPUT PORT
        LD      A,C     ;PUT PORT IN A
        LD      ($1+1),A  ;STUFF PORT
$1      IN      A,(0)     ;PORT LOADED ABOVE
        AND     E       ;MASK DATA
        LD      E,A
        PUSH    DE      ;RETURN RESULT ON STACK
        JP      (HL)    ;RETURN
        ;
        ;
        .PROC   OUTPUT,2
        ;
        POP     HL      ;GET RETURN ADDRESS
        POP     DE      ;GET DATA
        POP     BC      ;GET OUTPUT PORT
        LD      A,C     ;PUT PORT IN A
        LD      ($1+1),A  ;STUFF PORT
        LD      A,E     ;PUT DATA IN A
$1      OUT     (0),A     ;PORT LOADED ABOVE
        JP      (HL)    ;RETURN
        ;
        ;
        .END
        

